class Solution:
    def longestPalindrome(self, s: str) -> str:
        result = s[0]
        for i in range(len(s)-1):
            if  s[i] == s[i+1]:
                r = i+1
                while i>=0 and s[i] == s[r] and r < len(s):
                    i-=1
                    r+=1
                if len(result) < len(s[i+1: r]):
                    result = s[i+1:r]

            if i+2< len(s) and s[i] == s[i+2]:
                r = i+2
                while i>=0 and s[i] == s[r] and r < len(s):
                    i-=1
                    r+=1
                if len(result) < len(s[i+1: r]):
                    result = s[i+1:r]

        return result


                


